﻿<!--既做新增，又做修改，做设置路由，需要2套路由-->
@page "/employeeedit/{DepartmentId}"
@page "/employeeedit/{DepartmentId}/{EmployeeId}"

@using Covid.Shared.Dtos;


<h3>EmployeeEdit</h3>


@if (!Saved)
{
<!--
Model：    指定绑定的数据
    既可以使用原生的HTML标签，也可以使用封装的。
-->
                <EditForm Model="@Employee" OnValidSubmit="@HandValidSubmit" OnInvalidSubmit="@HandInValidSubmit">

                    <!--表单校验-->
                    <DataAnnotationsValidator />
                    <ValidationSummary></ValidationSummary>

                    <div class="form-group row">
                        <label for="no" class="col-sm-2 col-form-label">编号</label>
                        <div class="col-sm-10">
                            <InputText class="form-control" id="no" @bind-Value="@Employee.No"></InputText>
                            <ValidationMessage For="@(()=>Employee.No)"></ValidationMessage>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="name" class="col-sm-2 col-form-label">姓名</label>
                        <div class="col-sm-10">
                            <InputText class="form-control" id="name" @bind-Value="@Employee.Name"></InputText>
                            <ValidationMessage For="@(()=>Employee.Name)"></ValidationMessage>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="no" class="col-sm-2 col-form-label">出生日期</label>
                        <div class="col-sm-10">
                            <InputDate class="form-control" id="no" @bind-Value="@Employee.BirthDate"></InputDate>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="gender" class="col-sm-2 col-form-label">性别</label>
                        <div class="col-sm-10">
                            <InputSelect class="form-control" id="gender" @bind-Value="@Employee.Gender">
                                @foreach (var value in Enum.GetValues(typeof(Gender)))
                                    {
                                        <option value="@value">@value</option>
                                    }
                            </InputSelect>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="departmentId" class="col-sm-2 col-form-label">部门</label>
                        <div class="col-sm-10">
                            <InputSelect class="form-control" id="departmentId" @bind-Value="@EmployeeDepartmentId">
                                @foreach (var department in Departments)
                                    {
                                        <option value="@department.Id">@department.Name</option>
                                    }
                            </InputSelect>
                        </div>
                    </div>


                    <div class="form-group row offset-sm-2">
                        <!--删除操作-->
                        @if (!string.IsNullOrWhiteSpace(EmployeeId))
                        {
                        <button class="btn btn-danger" @onclick="@DeleteEmployee">删除</button>
                        }
                        &nbsp; &nbsp;
                        <!--提交按钮-->
                        <button type="submit" class="btn btn-primary">修改</button>
                        <!--返回-->
                        &nbsp; &nbsp;
                        <button class="btn btn-secondary" @onclick="@GoCack">返回</button>
                    </div>
                </EditForm> 
}
else
{

<div class="@CssClass" role="alert">
    @Message
</div>
}

